/* **************************************************************************
	
	Name of file: 	results_replication_do.do
	
	Author: 		Cameron Deal (cameron.h.deal@vanderbilt.edu)
									
	Project: 		Bostock and Public Opinion
	
	Dataset:		Nationscape 2019-2021
	
	Last Edited: 	18/July/2022
	
	Note:				
	
*************************************************************************** */

*set directory
cd "C:\Users\Cameron.Deal\Downloads\Bostock Replication\"
*cd "[Insert Path Here]"

*load data
use "nationscape_clean.dta", clear

*set macros
global indiv_controls "i.gender age age_squared i.unemployed i.educat i.race4 i.relig5 i.democrat i.republican"

*************************** RESULTS *******************************************
************************************************
* Table 1: The effect of employment protections on attitudes towards LGBT people
************************************************
*Column 1 
regress lgbt_fav_bin i.post i.treatment did i.state_factor i.week [pweight=weight], vce(cluster state)
eststo state_week
regress lgbt_fav_bin i.post i.treatment did $indiv_controls i.state_factor i.week [pweight=weight], vce(cluster state)
eststo indiv_controls
regress lgbt_fav_bin i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight], vce(cluster state)
eststo state_time

esttab, se keep(did) r2 star(* 0.10 ** 0.05 *** 0.01) label                 ///
    title(Binary LGBT Favorability (LPM, Weighted))      append
eststo clear

*Mean of outcome pre-bostock
mean lgbt_fav_bin if post==0 [pweight=weight]

*****Alternative cuts of outcome
*Top 1 vs. Bottom 3 (Column 2)
regress lgbt_fav_top i.post i.treatment did i.state_factor i.week [pweight=weight], vce(cluster state)
eststo state_week
regress lgbt_fav_top i.post i.treatment did $indiv_controls i.state_factor i.week [pweight=weight], vce(cluster state)
eststo indiv_controls
regress lgbt_fav_top i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight], vce(cluster state)
eststo state_trends

esttab, se keep(did) r2 star(* 0.10 ** 0.05 *** 0.01) label                 ///
    title(Top Category LGBT Favorability)      append
eststo clear

*Top 2 categories vs. bottom 2 categories (Column 3)
regress lgbt_fav_2cat i.post i.treatment did i.state_factor i.week [pweight=weight], vce(cluster state)
eststo state_week
regress lgbt_fav_2cat i.post i.treatment did $indiv_controls i.state_factor i.week [pweight=weight], vce(cluster state)
eststo indiv_controls
regress lgbt_fav_2cat i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight], vce(cluster state)
eststo state_trends

esttab, se keep(did) r2 star(* 0.10 ** 0.05 *** 0.01) label                 ///
    title(Middle Categories LGBT Favorability)      append
eststo clear


*Continuous (Column 4)
regress lgbt_fav_cont i.post i.treatment did i.state_factor i.week [pweight=weight], vce(cluster state)
eststo state_week
regress lgbt_fav_cont i.post i.treatment did $indiv_controls i.state_factor i.week [pweight=weight], vce(cluster state)
eststo indiv_controls
regress lgbt_fav_cont i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight], vce(cluster state)
eststo state_trends

esttab, se keep(did) r2 star(* 0.10 ** 0.05 *** 0.01) label                 ///
    title(Continuous LGBT Favorability)      append
eststo clear

*Treatment alternate cut- Indiana and Wisconsin are sexual orientation only, include them in treated
regress lgbt_fav_bin post##treatment_alt $indiv_controls i.state_factor i.week [pweight=weight], vce(cluster state)

************************************************
* Figure 1: Event Study 
************************************************
gen event_time = weeks_bin3 - 15
*Truncate Data:
replace event_time = -4 if event_time< -4
replace event_time = 4 if event_time>4
rename event_time rel
*
replace rel = 0 if treatment==0

tab rel, gen(rela)

rename rela1 pre4
rename rela2 pre3
rename rela3 pre2
rename rela4 ref
rename rela5 post0
rename rela6 post1
rename rela7 post2
rename rela8 post3 
rename rela9 post4

global event  pre4 pre3 pre2 post0 post1 post2 post3 post4 
*Full Sample
reg lgbt_fav_bin $event i.state_factor i.week $indiv_controls, vce(cluster state)
eststo reg1
	
	#delimit ;
 esttab reg1, 
         label se star(* 0.10 ** 0.05 *** 0.01)    
		title({Event Study for Bostock}) addnotes ("Source: Nationscape Data")
       keep( $event ) append ;
#delimit cr	
eststo clear

************************************************
* Table 2: Heterogeneity Analyses
************************************************
	
*Government Interest
regress lgbt_fav_bin i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight] if interested==1, vce(cluster state)
eststo gov_interest
regress lgbt_fav_bin i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight] if interested==0, vce(cluster state)
eststo notgov_interest
esttab, se keep(did) r2 star(* 0.10 ** 0.05 *** 0.01) label                 ///
    title(Government Interest)  
eststo clear
mean lgbt_fav_bin if post==0 [pweight=weight], over(interested)

*Party Affiliation
regress lgbt_fav_bin i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight] if democrat==1, vce(cluster state)
eststo democrat
regress lgbt_fav_bin i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight] if republican==1, vce(cluster state)
eststo republican
esttab, se keep(did) r2 star(* 0.10 ** 0.05 *** 0.01) label                 ///
    title(Party Affiliation)   append
	eststo clear
mean lgbt_fav_bin if post==0 & democrat==1 [pweight=weight]
mean lgbt_fav_bin if post==0 & republican==1 [pweight=weight]

*Gender 
regress lgbt_fav_bin i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight] if gender==1, vce(cluster state)
eststo female
regress lgbt_fav_bin i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight] if gender==2, vce(cluster state)
eststo male
esttab, se keep(did) r2 star(* 0.10 ** 0.05 *** 0.01) label                 ///
    title(Gender)   append
	eststo clear
mean lgbt_fav_bin if post==0 [pweight=weight], over(gender)

*Race=White
regress lgbt_fav_bin i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight] if race4==1, vce(cluster state)
eststo white
regress lgbt_fav_bin i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight] if race4!=1, vce(cluster state)
eststo nonwhite
esttab, se keep(did) r2 star(* 0.10 ** 0.05 *** 0.01) label                 ///
    title(Race) append
	eststo clear
mean lgbt_fav_bin if post==0 & race4==1 [pweight=weight]
mean lgbt_fav_bin if post==0 & race4!=1 [pweight=weight]

*Education
regress lgbt_fav_bin i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight] if educat==3, vce(cluster state)
eststo bachelors
regress lgbt_fav_bin i.post i.treatment did $indiv_controls i.state_factor##c.trend [pweight=weight] if educat!=3, vce(cluster state)
eststo no_bachelors
esttab, se keep(did) r2 star(* 0.10 ** 0.05 *** 0.01) label                 ///
    title(Education) append
	eststo clear
mean lgbt_fav_bin if post==0 & educat==3 [pweight=weight]
mean lgbt_fav_bin if post==0 & educat!=3 [pweight=weight]
